package android.pruebas.listview2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.pruebas.listview2.R;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.TextView;
import android.view.View;


/**
 * Lista con dos columnas.
 * @author luis
 *
 */
public class ListView2Activity extends ListActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		String[] paises = getResources().getStringArray(R.array.paises);
		List<HashMap<String,String>> lista = new ArrayList<HashMap<String,String>>();

		HashMap<String,String> hmap;
		for(int i = 0 ; i<paises.length; i++) {
			hmap = new HashMap<String,String>();
			hmap.put("codigo", ""+i);
			hmap.put("pais", paises[i]);
			lista.add(hmap);
		}

		SimpleAdapter a = new SimpleAdapter(this,lista,R.layout.list_item,
				new String[] {"codigo", "pais"}, new int[] {R.id.codigo, R.id.pais});
		setListAdapter(a);
		
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);

		lv.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				
				
				Toast.makeText(getApplicationContext(), view.toString(),
						Toast.LENGTH_SHORT).show();
			}
		});


	}


}